<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('在线实验项目列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>实验名称：</label>
                                <input type="text" name="experimentName"/>
                            </li>
                            <li>
                                <label>是否开放：</label>
                                <!--<input type="text" name="ifOpen"/>-->
                                <select name="ifOpen">
                                    <option value="">请选择</option>
                                    <option value="1">开放</option>
                                    <option value="2">不开放</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:experiment:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:experiment:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:experiment:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:experiment:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:experiment:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:experiment:remove')}]];
        var prefix = ctx + "system/experiment";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "在线实验项目",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'experimentId',
                    title: '实验编号',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field : 'experimentPhoto',
                    title : '实验图片',
                    formatter: function(value, row, index) {
                        return $.table.imageView(ctx+value);
                    }
                },
                {
                    field: 'experimentName',
                    title: '实验名称'
                },
                {
                    field: 'experimentHref',
                    title: '实验链接'
                },
                {
                        visible: editFlag == 'hidden' ? false : true,
                        title: '是否开放',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return statusTools(row);
                        }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                       /* actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="asign(\'' + row.experimentId + '\')"><i class="fa fa-save"></i>指派</a>&nbsp;');*/
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.experimentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeExperiment(\'' + row.experimentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function removeExperiment(id){
            $.modal.confirm("删除实验项目,同时删除所有实验成绩。", function() {
                $.operate.remove(id);
            })
        }

        /* 开放状态显示 */
        function statusTools(row) {
            if (row.ifOpen == 2) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.experimentId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.experimentId + '\')"></i> ';
            }
        }

        /* 实验项目不开放 */
        function disable(experimentId) {
            $.modal.confirm("确认不开放该实验吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "experimentId": experimentId, "ifOpen": 2 });
            })
        }

        /* 实验项目开放 */
        function enable(experimentId) {
            $.modal.confirm("确认要开放该实验吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "experimentId": experimentId, "ifOpen": 1 });
            })
        }

        /**
         * 指派教师
         */
        function asign(val) {
            $.modal.open('指派教师',prefix + '/asign?experimentId='+val,800,800);
        }
    </script>
</body>
</html>